package com.tang.algorithm.swordFingerOffer;

/**
 * @author tlm
 * @version 1.0
 * @date 2020/4/29 18:59
 * 删除链表的节点
 * <p>
 * https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/
 */
public class DeleteTheNodeOfTheLinkedList {
    public static void main(String[] args) {
        ListNode listNode = new ListNode(-3);
        listNode.next=new ListNode(5);
        listNode.next.next=new ListNode(-99);
        listNode=deleteNode(listNode,-99);
        System.out.println(listNode.val+","+listNode.next.val);

    }
    public static ListNode deleteNode(ListNode head, int val) {
        if (head == null) return null;
        ListNode temp = new ListNode(0);
        temp.next=head;
        if (head.val == val) return head.next;


        while (temp.next!=null ) {
            if (temp.next.val == val) {
                temp.next = temp.next.next;
                return head;
            }
            temp = temp.next;
        }


        return head;
    }
    static void hasNext(ListNode temp){

    }
}

